#ifndef REQUESTMANAGER_HPP
#define REQUESTMANAGER_HPP

#include "Runnable.hpp"
#include "Client.hpp"
#include "ClientManager.hpp"

#include <stdlib.h>
#include <string.h>
#include <queue>
#include <pthread.h>

class Request
{
	public:
	Client* client;
	char* request;

	Request(Client*& client,char*& request);
	~Request();
};


/**
 * list & process all clients' requests
 * @need : clientManager, 
 * @runnable
 **/
class RequestManager:public Runnable
{
	public:
	//  FIFO {request + client*} (STL::queue)
	std::queue<Request> requestQueue;

	/* lock & cond */
	pthread_mutex_t lock;
	pthread_cond_t cond;

	/* clientManager */
	ClientManager* clientManager;


	/* constructor */
	RequestManager(ClientManager*);

	/* destructor */
	~RequestManager();

	/* external method : add a request (lock) */
	void addRequest(Client* client,char* request);

	/* internal method : handle request ~ clients + client.SendList + game... */
	int handleRequest(Request&);

	/* thread run : handle requests -> client vars + client sendList */
	virtual void run();
};

#endif
